<?php


namespace App\Http\Controllers\Api;


use App\Http\Controllers\Controller;
use App\Services\Api\UploadService;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class UploadController extends Controller
{
    private $uploadService;

    public function __construct(UploadService $uploadService)
    {
        $this->uploadService = $uploadService;
    }

    public function picture(Request $request)
    {
        return $request->all();
        try{
            $data = $this->uploadService->setPicture($request);
            return $this->wrapSuccessReturn(compact('data'));
        }catch (\Exception $exception){
            return $this->wrapErrorReturn($exception);
        }
    }

    /*
     * 上传图片测试
     */
    public function upload_img(Request $request)
    {
        if(!empty($_FILES['logo'])){
            Log::info($_FILES["logo"]["type"]."---".$_FILES["logo"]["name"]."---".$_FILES["logo"]["size"]);

            $uploaddir = 'app/public/uploads/';
            $uploadfile = $uploaddir . basename($_FILES['logo']['name']);
            Log::info($uploadfile);
            if (move_uploaded_file($_FILES['logo']['tmp_name'], storage_path($uploadfile))) {
                Log::info( "File is valid, and was successfully uploaded.\n");
            } else {
                Log::info(  "Possible file upload attack!\n");
            }


        }


        $ret['err']     = 0;
        $ret['msg']     = '成功';

        return response()->json($ret);

    }
}
